<?php

// 客服系统配置模型

namespace app\api\model;

use app\admin\model\Attachment;
use think\facade\Request;
use think\Model;

class Service extends Model
{

    // 数据表名称,不包括表前缀
    protected $name = 'vpn_service';
    // 数据表主键
    protected $pk = 'cid';
    // 时间字段取出后的默认时间格式
    protected $dateFormat = false;

    public function getIconAttr($value)
    {
        $base_file = Request::baseFile();
        $base_dir  = substr($base_file, 0, strripos($base_file, '/') + 1);
        if ($value) {
            $result = Attachment::where('id', $value)->field('path,driver,thumb')->find();
            if ($result) {
                if ($result['driver'] == 'local') {
                    return $result['thumb'] != '' ? $base_dir . $result['thumb'] : $base_dir . $result['path'];
                } else {
                    return $result['thumb'] != '' ? $result['thumb'] : $result['path'];
                }
            }
        }
        return  $base_dir . 'static/' . 'admin/img/none.png';
    }
}
